﻿namespace com.stifel.BranchMgmt
{
    using System.Collections.Generic;
    using System.Text;
    using System.Web.UI.WebControls;

    using com.stifel.BranchMgmtDao;
    using com.stifel.Web;

    using Microsoft.SharePoint;

    public partial class BranchMgmtViewUserControl
    {
        #region Fields

        List<uiBusinessUnit_Data> _uiBusinessUnits_Data_List;

        #endregion Fields

        #region Properties

        List<uiBusinessUnit_Data> uiBusinessUnits_Data_List
        {
            get
            {
                if ( _uiBusinessUnits_Data_List == null )
                    _uiBusinessUnits_Data_List = new List<uiBusinessUnit_Data>( );
                return _uiBusinessUnits_Data_List;
            }
            set
            {
                _uiBusinessUnits_Data_List = value;
            }
        }

        #endregion Properties

        #region Methods

        void loadBasics( int branchId )
        {
            StifelBranchInfoDao dao = new StifelBranchInfoDao( SPContext.Current.Web.Url );
            StifelBranchInfo value = dao.Get( branchId );
            uiBranchId.Text = value.BranchLocationIdentifier;
            loadBranchAddress( value );
            uiSiteId.Text = "";// TODO
            uiSpeedDial.Text = "";//TODO
            uiThompsonIdPrefix.Text = "";//TODO
            uiTimeZone.Text = value.TimeZoneLookupusr_tz_value;
            uiBroadcastIp.Text = "";//TODO
            uiBranchType.Text = value.BranchTypeTitle;
            uiPriceServer.Text = "";//TODO
            loadBusinessUnits( value );
        }

        void loadBranchAddress( StifelBranchInfo value )
        {
            HtmlDivisionControl div = new HtmlDivisionControl( );
            StringBuilder sb = new StringBuilder( );
            if ( !string.IsNullOrEmpty( value.BranchStreetAddress ) )
                sb.AppendFormat( "{0}\t", value.BranchStreetAddress );
            if ( !string.IsNullOrEmpty( value.BranchSuiteAddress ) )
                sb.AppendFormat( "{0}\t", value.BranchSuiteAddress );
            if ( !string.IsNullOrEmpty( value.BranchCity ) )
                sb.AppendFormat( "{0},", value.BranchCity );
            if ( !string.IsNullOrEmpty( value.USStatesLookupusr_us_value ) )
                sb.AppendFormat( " {0}", value.USStatesLookupusr_us_value );
            if ( !string.IsNullOrEmpty( value.BranchZipcode ) )
                sb.AppendFormat( " {0}", value.BranchZipcode );
            string s = sb.ToString( ).Trim( ).Replace( "\t", "<br />" );
            sb = null;
            Label label = new Label
            {
                Text = s,
                CssClass = "ms-vb"
            };
            div.Controls.Add( label );
            uiAddress.Controls.Add( div );
        }

        void loadBusinessUnits( StifelBranchInfo value )
        {
            //TODO
            uiBusinessUnit_Repeater.DataSource = uiBusinessUnits_Data_List;
            uiBusinessUnit_Repeater.DataBind( );
        }

        #endregion Methods

        #region Nested Types

        protected class uiBusinessUnit_Data
        {
            #region Constructors

            public uiBusinessUnit_Data( object value )
            {
            }

            #endregion Constructors

            #region Properties

            public string BusinessUnit
            {
                get;
                set;
            }

            public string CheckCode
            {
                get;
                set;
            }

            public string DestCode
            {
                get;
                set;
            }

            public string ORG
            {
                get;
                set;
            }

            public string value
            {
                get;
                set;
            }

            public string WireCode
            {
                get;
                set;
            }

            #endregion Properties
        }

        #endregion Nested Types
    }
}